package my.code.charpter16;

import java.util.Arrays;

/**
 * 个体
 * @author xuyuji
 *
 */
public class Individual {
	int[] gene;		//基因组
	int fitness;	//适应度
    double rf;		//选择概率
    double cf;		//积累选择率
    
    @Override
    public String toString() {
    	StringBuilder sb = new StringBuilder();
    	sb.append("{");
    	sb.append("gene:").append("[");
    	if(gene.length > 0){
    		sb.append(gene[0]);
    		for(int i = 1; i < gene.length; i++){
    			sb.append(",").append(gene[i]);
    		}
    	}
    	sb.append("]").append(",");
    	sb.append("\tfitness:").append(fitness).append(",");
    	sb.append("\trf:").append(rf).append(",");
    	sb.append("\tcf:").append(cf);
    	sb.append("}");
    	return sb.toString();
    }
    
    public static Individual valueOf(Individual old){
    	Individual g = new Individual();
    	g.gene = Arrays.copyOf(old.gene, old.gene.length);
    	g.fitness = old.fitness;
    	return g;
    }
}
